package com.tree.web;

import com.tree.entity.Article;
import com.tree.entity.Flower;
import com.tree.entity.Rtree;
import com.tree.entity.TreeNew;
import com.tree.service.*;
import com.tree.util.HttpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;

@Controller
@RequestMapping(value = "/search")
public class searchController {

    private static String error = "没有此项内容";
    @Autowired
    private ArticleService articleService;
    @Autowired
    private TreeNewService treeNewService;
    @Autowired
    private FlowerService flowerService;
    @Autowired
    private RtreeService rtreeService;

    //查找花和树
    @RequestMapping(value = "/research")
    private String search(@RequestParam("value") String value, ModelMap modelMap){

        List<Rtree> rtreeList = rtreeService.querySearch(value);
        //判断搜索的古树是否为空
        if (rtreeList.size() > 0)
            modelMap.addAttribute("treeList",rtreeList);
        else
            modelMap.addAttribute("error",error);
        //判断搜索的花卉是否为空
        List<Flower> flowerList = flowerService.querySearch(value);
        if (flowerList.size() > 0)
            modelMap.addAttribute("flowerList",flowerList);
        else
            modelMap.addAttribute("error",error);
        //查找论文
        List<Article> articleList = articleService.querySearch(value);
        if (articleList.size() > 0)
            modelMap.addAttribute("articleList",articleList);
        else
            modelMap.addAttribute("error",error);
        //查找新闻
        List<TreeNew> treeNewList = treeNewService.querySearch(value);
        if (treeNewList.size() > 0)
            modelMap.addAttribute("treeNewList",treeNewList);
        else
            modelMap.addAttribute("error",error);

        return "search/search";
    }
}
